home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Codigo / Cuadros de diálogo / FontAndColorDialogs / FontAndColorDialogs.cs next >
Encoding:
Text File  |  2002-05-23  |  1.9 KB  |  61 lines

  1. //--------------------------------------------------
  2. // FontAndColorDialogs.cs ⌐ 2001 by Charles Petzold
  3. //--------------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. class FontAndColorDialogs:Form
  9. {
  10.      public static void Main()
  11.      {
  12.           Application.Run(new FontAndColorDialogs());
  13.      }
  14.      public FontAndColorDialogs()
  15.      {
  16.           Text = "Dißlogos Fuente y Color";
  17.           ResizeRedraw = true;
  18.  
  19.           Menu = new MainMenu();
  20.           Menu.MenuItems.Add("&Formato");
  21.           Menu.MenuItems[0].MenuItems.Add("&Fuente...",
  22.                                         new EventHandler(MenuFontOnClick));
  23.           Menu.MenuItems[0].MenuItems.Add("&Color de Fondo...",
  24.                                         new EventHandler(MenuColorOnClick));
  25.      }
  26.      void MenuFontOnClick(object obj, EventArgs ea)
  27.      {
  28.           FontDialog fontdlg = new FontDialog();
  29.  
  30.           fontdlg.Font  = Font;
  31.           fontdlg.Color = ForeColor;
  32.           fontdlg.ShowColor = true;
  33.  
  34.           if(fontdlg.ShowDialog() == DialogResult.OK)
  35.           {
  36.                Font = fontdlg.Font;
  37.                ForeColor  = fontdlg.Color;
  38.                Invalidate();
  39.           }
  40.      }
  41.      void MenuColorOnClick(object obj, EventArgs ea)
  42.      {
  43.           ColorDialog clrdlg = new ColorDialog();
  44.  
  45.           clrdlg.Color = BackColor;
  46.  
  47.           if (clrdlg.ShowDialog() == DialogResult.OK)
  48.                BackColor = clrdlg.Color;
  49.      }
  50.      protected override void OnPaint(PaintEventArgs pea)
  51.      {
  52.           Graphics     grfx   = pea.Graphics;
  53.           StringFormat strfmt = new StringFormat();
  54.  
  55.           strfmt.Alignment = strfmt.LineAlignment = StringAlignment.Center;
  56.  
  57.           grfx.DrawString("íHola, cuadros de dißlogo comunes!", Font, 
  58.                           new SolidBrush(ForeColor), 
  59.                           this.ClientRectangle, strfmt);
  60.      }
  61. }